<template>
    <div class="shop">
        <div class="search">
            <span class="iconfont search_back" @click="toback()">&#xe697;</span>
            <div class="search_content">
                <span class="iconfont search_content_icon">&#xe632;</span>
                <input type="text" class="search_content_input" placeholder="请输入商品名称">
            </div>
        </div>
        <div class="shop_info">
            <Inshop :shopInfo="shop"></Inshop>
        </div>
        <div class="content">
            <div class="category">
                <div class="category_item" @click="categoryname = ''; categoryid = 0"
                    :class="{ 'category_item--active': categoryid == 0 }">全部商品</div>
                <div class="category_item" v-for="cate, i in category"
                    @click="categoryname = cate.name; categoryid = cate.id"
                    :class="{ 'category_item--active': cate.id == categoryid }">{{ cate.name }}</div>
            </div>
            <div class="product">
                <div v-for="cate in category">
                    <div v-if="isshop(cate.name)">
                        <div v-for="e in cate.list">
                            <Product :productInfo="e" :shopid='shop.id'></Product>
                        </div>
                    </div>
                </div>

            </div>
        </div>
 <CartBottom :shopid='shop.id'></CartBottom>

    </div>
</template>
<script setup>
import { useRoute, useRouter } from 'vue-router'
import useshopstore from "@/stores/shop.js"
import Inshop from '@/components/Inshop.vue';
import { ref } from 'vue';
import Product from '@/components/Product.vue';
import CartBottom from '@/components/CartBottom.vue'
const route = useRoute()
const router = useRouter()
const i = route.query.i
const shopstore = useshopstore()
const shop = shopstore.nearByList[i]
const category = shop.category
let categoryname = ref('')
let categoryid = ref(0)

console.log(category);



function isshop(name) {
    return name.indexOf(categoryname.value)+1
}
function toback() {
    router.go(-1)
}
</script>
<style lang="scss" scoped>
@import "@/style/viriables.scss";

.shop {

    //搜索
    .search {
        margin: .18rem;
        display: flex;
        align-items: center;

        &_back {
            font-size: .24rem;
            margin-right: .08rem;
            color: #b6b6b6;
        }

        &_content {
            flex: 1;
            height: .32rem;
            background-color: #f5f5f5;
            border-radius: .16rem;
            display: flex;
            align-items: center;

            &_icon {
                color: #b6b6b6;
                margin: 0 .12rem;
            }

            &_input {
                border: none;
                outline: none;
                background: none;
                width: 100%;
                height: .32rem;
            }
        }
    }

    //商店信息
    .shop_info {
        margin: 0 .18rem;
    }

    // 内容
    .content {
        position: absolute;
        left: 0;
        right: 0;
        top: 1.7rem;
        bottom: .5rem;
        display: flex;

        .category {
            overflow-y: scroll;
            width: .78rem;
            background-color: #f5f5f5;

            &_item {
                line-height: .4rem;
                font-size: .14rem;
                text-align: center;
                color: $content_fontcolor;

                &--active {
                    background-color: $bgColor;
                }
            }
        }

        .product {
            flex: 1;
            overflow-y: scroll;
        }
    }
}
</style>